package cart

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"go.uber.org/zap"
	"homepage_srv/homepage"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartAddNumLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartAddNumLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartAddNumLogic {
	return &CartAddNumLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 给购物车中的商品的数量添加
func (l *CartAddNumLogic) CartAddNum(req *types.CartAddNumRequest) (resp *types.Response, err error) {
	num, err := l.svcCtx.HomepageGrpc.CartAddNum(l.ctx, &homepage.CartAddNumRequest{
		UserId:  req.UserId,
		GoodsId: req.GoodId,
		SkuId:   req.SkuId,
	})
	if err != nil {
		pkg.Error("添加失败", zap.Error(err))
		return nil, err
	}
	return respons.Success(num), nil
}
